#!/bin/sh

#= auto build example

## hyphop ##

set -e
cd "$(dirname "$0")"

#export LINUX_VER=linux-5.7.7

DONE(){
    s_=$?
    COMPLITED=$(date +%s)
    DURATION=$((COMPLITED-STARTED))
    echo "DONE: duration $DURATION sec"
    exit
}

STARTED=$(date +%s)

#sleep 1
#DONE
#echo OOPS
#exit 2

. ./config.conf

export KERNEL_SOURCE_DIR="$KERNEL_SOURCE_DIR"

./$kernel_prepare

CHK=1 ./patch_ || {
#./patch_ ../patches/$LINUX_VER/*.patch
./patch_ ../patches/$LINUX_VER*/*.patch
./patch_ ../patches/linux-krescue/*.patch
LAST=1 ./patch_
}

./make_kernel_mainline_vimsX -n

[ "OK" ] && {
./kernel_config ../files/configs/mmc_m
[ "$DRM_NO" ] && \
./kernel_config ../files/configs/drm_n
[ "$DRM_MODULE" ] && \
./kernel_config ../files/configs/drm_m
./kernel_config ../files/configs/eth2_y
[ "$ETH_AS_MODULE" ] && \
./kernel_config ../files/configs/eth2_m
./kernel_config ../files/configs/usb_storage_m
./kernel_config ../files/configs/small_size_y
}

NOPOST=1 ./make_kernel_mainline_vimsX dtbs || echo "[w] ups...">&2

[ "$TESTONLY" ] && {
    echo "[i] OK testonly mode"
    DONE
}

./make_kernel_mainline_vimsX

[ "$DTB_ONLY" ] && DONE
[ "$DTB_AND_IMAGE" ] && DONE

[ "$NOMOD" ] || {
TAR=1 IPK=1 ./make_kernel_mainline_vimsX_modules
./make_kernel_opkgs
}

DONE